package App.Event;

import net.coobird.thumbnailator.Thumbnails;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by yu on 2017/7/19.
 */
@Component
public class ImageEventListener
{

    //对图片进行压缩操作
    @Async
    @EventListener
    public void  handler(ImageEvent event)  {
        try {
            Thumbnails.of(event.getInputStream()).size(300,300).toFile(event.getEventContent());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
